package com.dzzw.Servlet.AttendanceServlet;

import com.dzzw.Dao.AttendanceDao;
import com.dzzw.Model.Attendance;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;

@WebServlet("/View/SignOutServlet")
public class SignOutServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private final AttendanceDao attendanceDao = new AttendanceDao();
    public SignOutServlet(){
        super();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int employee_id = Integer.parseInt(request.getParameter("employee_id"));
        Attendance attendance = new Attendance();
        attendance.setEmployee_id(employee_id);
        try {
            attendanceDao.SignOut(attendance);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("签退成功！");
        response.sendRedirect("/View/FindAllAttendanceByEmployeeId.jsp");
    }
}
